package com.atguigu.filter.filter;

import jakarta.servlet.*;

import java.io.IOException;

public class Filter02LifeCycle implements Filter {

    public Filter02LifeCycle() {
        System.out.println("Filter02LifeCycle 执行了构造器，创建了对象");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Filter02LifeCycle 执行了 init() 方法，完成了初始化");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("-----------------------Filter02LifeCycle 开始执行-----------------------");
        System.out.println("Filter02LifeCycle 拦截到了请求");

        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("-----------------------Filter02LifeCycle 结束执行-----------------------");
    }

    @Override
    public void destroy() {
        System.out.println("Filter02LifeCycle 执行了 destroy() 方法，完成了清理工作");
    }
}
